module DRb
  def self.start_service_on_any_port(uri = nil, front = nil, config = nil)
    uri = URI.parse(uri.to_s)
    uri.scheme = "druby"
    uri.host ||= "0.0.0.0"
    uri.port ||= 9001
    result = nil
    
    while !result && uri.port <= 65535
      begin
        result = start_service(uri.to_s, front, config)
      rescue Errno::EADDRINUSE
        uri.port += 1
      end
    end
    
    result
  end
end